package admin.board.board_list.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import admin.board.board_list.dao.BoardlistDao;
import admin.board.board_list.dto.BoardlistDto;
import admin.board.category.dao.CategoryDao;
import admin.board.category.dto.CategoryDto;
import admin.common.AdminUtil;

import com.opensymphony.xwork2.ActionSupport;

public class WriteAction extends ActionSupport {
	private BoardlistDto dto;
	private BoardlistDao dao;
	private CategoryDao categoryDao;
	private List<CategoryDto> categoryList;
	private List<Integer> possibleNumList;
	
	private int board_no;
	private int category_no;
	private String board_name;
	private int view_level;
	private String link_page;

	public WriteAction() {
		dao = BoardlistDao.getInstance();
	}
	
	public String form() throws SQLException {
		categoryDao = CategoryDao.getInstance();
		categoryList = categoryDao.list();
		possibleNumList = AdminUtil.checkPossibleNum(1, 10, 1, dao);
		
		return SUCCESS;
	}
	
	public String possibleNumCheck() throws SQLException {
		possibleNumList = AdminUtil.checkPossibleNum(
				category_no*10-9, category_no*10, category_no, dao);
		
		return SUCCESS;
	}
	
	public String execute() throws Exception {
		dto = new BoardlistDto();
		dto.setAll(board_no, board_name, view_level, link_page, category_no);
		dao.insert(dto);
		
		return SUCCESS;
	}

	public BoardlistDto getDto() {
		return dto;
	}
	
	public List<Integer> getPossibleNumList() {
		return possibleNumList;
	}
	
	public List<CategoryDto> getCategoryList() {
		return categoryList;
	}
	
	public int getBoard_no() {
		return board_no;
	}
	public void setBoard_no(int board_no) {
		this.board_no = board_no;
	}
	
	public int getCategory_no() {
		return category_no;
	}

	public void setCategory_no(int category_no) {
		this.category_no = category_no;
	}

	public String getBoard_name() {
		return board_name;
	}

	public void setBoard_name(String board_name) {
		this.board_name = board_name;
	}

	public int getView_level() {
		return view_level;
	}

	public void setView_level(int view_level) {
		this.view_level = view_level;
	}

	public String getLink_page() {
		return link_page;
	}

	public void setLink_page(String link_page) {
		this.link_page = link_page;
	}
}
